﻿using System;
using System.Windows.Controls;

using VSTalk.Engine.View;
using VSTalk.Engine.ViewModel.Messenger;

namespace VSTalk.Engine.Core.EnvironmentManagers.UI.Builders
{
    public class ChatControlBuilder : IControlBuilder
    {
        private ChatFrameViewModel _context;
        private CommonChatFrame _control;

        public Type ControlType { get { return typeof(CommonChatFrame); } }
        public Type ContextType { get { return typeof(ChatFrameViewModel); } }
        public UserControl Create()
        {
            if (_context == null)
            {
                _context = new ChatFrameViewModel();
                _context.StartListen();
            }
            if (_control == null)
            {
                _control = new CommonChatFrame();
            }
            if (_control.DataContext == _context)
            {
                return _control;
            }
            _control.DataContext = _context;
            return _control;
        }
    }
}